package com.px.plan.controller;

import com.px.common.core.controller.BaseController;
import com.px.common.core.domain.AjaxResult;
import com.px.common.core.domain.entity.SysUser;
import com.px.common.core.page.TableDataInfo;
import com.px.common.utils.StringUtils;
import com.px.framework.aes.AesSecurityParameter;
import com.px.plan.domain.PlanActionUser;
import com.px.plan.service.IPlanActionUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 行动关联人员Controller
 *
 * @author WRJ
 * @date 2024-08
 */
@Api("行动关联人员")
@RestController
@RequestMapping("/plan/user")
public class PlanActionUserController extends BaseController
{
    @Autowired
    private IPlanActionUserService planActionUserService;

    /**
     * 查询行动关联人员列表
     */
    @ApiOperation("查询行动关联人员列表")
    @PreAuthorize("@ss.hasPermi('plan:action:list')")
    @GetMapping("/list")
    @AesSecurityParameter(outEncode = true)
    public TableDataInfo list(PlanActionUser planActionUser)
    {
        startPage();
        List<PlanActionUser> list = planActionUserService.selectPlanActionUserList(planActionUser);
        return getDataTable(list);
    }

    /**
     * 查询行动关联人员列表
     */
    @ApiOperation("可关联人员列表")
    @PreAuthorize("@ss.hasPermi('plan:action:edit')")
    @GetMapping("selectUser")
    @AesSecurityParameter(outEncode = true)
    public AjaxResult selectUser(@RequestParam(value = "nickName",required = false) String nickName)
    {
        List<SysUser> userList = planActionUserService.selectUser();
        if (StringUtils.isNotEmpty(nickName)) {
            userList = userList.stream().filter(u -> u.getNickName().contains(nickName)).collect(Collectors.toList());
        }
        return AjaxResult.success(userList);
    }

    /**
     * 获取行动关联人员详细信息
     */
    @ApiOperation("获取行动关联人员详细信息")
    @PreAuthorize("@ss.hasPermi('plan:action:list')")
    @GetMapping(value = "/{id}")
    @AesSecurityParameter(outEncode = true)
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(planActionUserService.selectPlanActionUserById(id));
    }

    /**
     * 获取行动关联人员详细信息
     */
    @ApiOperation("获取行动中飞手及设备信息")
    @PreAuthorize("@ss.hasPermi('plan:action:list')")
    @GetMapping(value = "/getFlyingInfo")
    @AesSecurityParameter(outEncode = true)
    public AjaxResult getFlyingInfo(@RequestParam("actionId") Long actionId)
    {
        return success(planActionUserService.getFlyingInfo(actionId));
    }

    /**
     * 获取行动关联人员详细信息
     */
    @ApiOperation("获取行动中特勤人员及设备信息")
    @PreAuthorize("@ss.hasPermi('plan:action:list')")
    @GetMapping(value = "getSecretInfo")
    @AesSecurityParameter(outEncode = true)
    public AjaxResult getSecretInfo(@RequestParam("actionId") Long actionId)
    {
        return success(planActionUserService.getSecretInfo(actionId));
    }

}
